import * as PIXI from 'pixi.js';
import listener from '../../../listener';
import StageConf from '../../conf/StageConf';
import ScalerUtil from '../../util/ScalerUtil';
import ShapeView from '../item/ShapeView';

export default class ShapeLayer extends PIXI.Sprite{

    shapeViews:ShapeView[] = [];

    constructor(){
        super();
        
        this.init();
    }

    init(){
        this.draw();
        
        // listener.on("add", (str:string) => {
        //     var points:PIXI.Point[] = [];
        //     var list = str.replace(/\s/g, "").split(",");
        //     for(var i = 0, l = list.length; i < l; i += 2){
        //         var x:number = Number(list[i]);
        //         var y:number = Number(list[i + 1]);
        //         var point:PIXI.Point = new PIXI.Point(x, y);
        //         points.push(point);
        //     }
        //     var shapeView = new ShapeView(points);
        //     this.addChild(shapeView);
        //     this.shapeViews.push(shapeView);
        // })

        // listener.on("clear", () => {
        //     this.removeChildren();
        //     this.shapeViews = [];
        // })
    }

    clear(){
        this.shapeViews = [];
        this.removeChildren();
    }

    addPoints(points:PIXI.Point[]){
        var shapeView = new ShapeView(points);
        this.addChild(shapeView);
        this.shapeViews.push(shapeView);
    }

    draw(){
        this.shapeViews.forEach(item => item.draw());
    }
    
}